namespace Yaaf.WP7.NativeAccess.Helper
{
    using System.IO;
    using System.IO.IsolatedStorage;

    public static class IsolatedStorageFileExtensions
    {

        public static void CopyFile(this IsolatedStorageFile storage, string source, string dest)
        {
            using (var sourceFile = storage.OpenFile(source, FileMode.Open, FileAccess.Read))
            {
                const int bufferLen = 1024 * 1024;
                var buffer = new byte[bufferLen];
                int read;
                using (var destFile = storage.OpenFile(dest, FileMode.Create, FileAccess.Write))
                {
                    while ((read = sourceFile.Read(buffer, 0, bufferLen)) > 0)
                    {
                        destFile.Write(buffer, 0, read);
                    }
                }
            }
        }

        public static void MoveFile(this IsolatedStorageFile storage, string source, string dest)
        {
            storage.CopyFile(source, dest);
            storage.DeleteFile(source);
        }
    }
}